<?php

namespace apiend\modules\inventory\models;

use Yii;
use yii\db\Exception;
use yii\helpers\Json;
use common\helpers\ArrayHelper;
use common\models\bill\Bill;
use common\models\bill\BillData;
use common\models\bill\BillType;
use common\models\rfid\Rfid;
use common\models\inventory\InventoryBatch;

/**
 * 创建盘点批次模型
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class BatchForm extends \common\base\Model {

    /**
     * @var string 用户UID
     */
    public $user_id;

    /**
     * @var string 用户UID
     */
    public $type_id;

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['user_id', 'type_id'], 'required'],
            [['user_id', 'type_id'], 'integer'],
        ];
    }

    /**
     * 保存动态信息（发布&修改）
     */
    public function save() {
        if (!$this->validate()) {
            return $this->dumpError('提交失败');
        }
        $model = new InventoryBatch();
        $model->attributes = $this->attributes;
        $model->status = InventoryBatch::STATUS_DEFAULT;
        if (!$model->save()) {
            return $model->dumpError();
        }
        return $model->id;
    }

}
